// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Documents;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace SerialCommand
{
    public sealed class TextBoxStream : Control
    {
        public TextBoxStream()
        {
            this.DefaultStyleKey = typeof(TextBoxStream);
        }
        DependencyProperty TextProperty = DependencyProperty.Register(nameof(Text),
                                            typeof(string),
                                            typeof(TextBoxStream),
                                            new PropertyMetadata(default(string),
                                            new PropertyChangedCallback(OnTextChanged)));
        public string Text
        {
            get => (string)GetValue(TextProperty);
            set => SetValue(TextProperty, value);
        }
        DependencyProperty LineHeightProperty = DependencyProperty.Register(nameof(LineHeight),
                                    typeof(int),
                                    typeof(TextBoxStream),
                                    new PropertyMetadata(default(int)));
        public int LineHeight
        {
            get => (int)GetValue(LineHeightProperty);
            set => SetValue(LineHeightProperty, value);
        }
        public bool HasTextValue { get; set; }
        
        private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TextBoxStream labelControl = d as TextBoxStream; //null checks omitted
            String s = e.NewValue as String; //null checks omitted
            if (s == String.Empty)
            {
                labelControl.HasTextValue = false;
            }
            else
            {
                labelControl.HasTextValue = true;
            }
        }
    }
}
